
<script type="text/javascript">
<!--
	$(function(){
		$("#checkButton").button();
		$(".button").button().click(function(){
			if($(this).val() != 'finish'){
				$(this).parent().slideUp().next().fadeIn();
			}
		});

		var str = '';
		$("input[name=sel_table]").click(function(){
			if($(this).attr("checked") ==true){
				str += ','+$(this).val();
			}
			$("#sel_tables").val(str);
//			alert(str.substring(1,str.length);
		});

//		$("#dblist").load("<?php echo $this->createUrl('menulist',array('r'=>time()));?>");

		//两级连动
		$("#MenuForm_type").change(function(){
//			alert($(this).val());
			$.getJSON("<?php echo $this->createUrl('children');?>",{'cid':$(this).val()},function(msg){
//				alert(msg);
//		var msg = {"7":"\u76f8\u518c","8":"|\uff0d\u6536\u85cf\u7f8e\u56fe","9":"|\uff0d\u592a\u6e56\u7f8e\u666f","11":"|\uff0d\u6f2b\u753b"}		
//				$("#Category_cate_pid").html(msg);
//				dd = "";
				
				var pid = document.getElementById("Category_cate_pid");

				//清除所有已有选项
				while(pid.childNodes.length>0){
					pid.removeChild(pid.childNodes[0]);
				}
				$.each(msg,function(k,v){
//					dd += (k+v);

					
					var option = new Option(v,k);
					pid.options.add(option);
				});
//				alert(dd);
			});
			
		});
	});

	function chooseType(){
		if($("#backupWay").val() == "All"){
			$("#dataAll").show();
		}else if($("#backupWay").val() == "topmenu"){
			$("#MenuForm_type").parent().parent().hide().replaceWith('<input type="hidden" id="MenuForm_type" value="11" />');
			$("#MenuForm_pid").parent().parent().hide().replaceWith('<input type="hidden" id="MenuForm_pid" value="0" />');
			$("#menuform").show();
		}else{
			$("#menuform").show();
		}
	}

	function submitWay(){
		$(".hide").hide();
		$("#stepLoading").show();
	}

	function back(object){
		
		object.parent().prev().fadeIn().slideDown();
		$("#step2>div").hide();
	}

	function backupAll(){

		var ids = getIds();
		//检测是否已经增加了相关数据
		
		if(ids.length > 0){
			for(i in ids){
				$.post("<?php echo $this->createUrl('checkadditem'); ?>",{'id':ids[i]},function(data){
					if(data == 'ok'){
						
						ids.splice(i,1);
					}
					alert(data);
				});
			}
			if(ids.length == 0){
				alert("所选分类数据已经导入");
			}else{
				ids = ids.join('-');
//				alert(ids);
				$.post("<?php echo $this->createUrl('importmenus');?>",{'ids':ids},function(data){
					$("#dblist").html(data);
				});
			}
			
		}
		
	}

	function createMenu(){

		


		
//		confirm = confirm("确实要备份该数据库所有内容？");
//		if(confirm){
//			submitWay();
//			var tables = $("#sel_tables").val();
//			tables = tables.substring(1,tables.length).split(',');
////			alert(tables.length);
//			for(i=0;i<tables.length;i++){
//				$.post("<?php echo $this->createUrl('savetable');?>",{'table':tables[i]},function(data){
//					alert(data);
//				});
//			}
//		}else{
//			$("#dataTable").show();
//		}
	}

	function getIds(){
		var ids = new Array();
		$("input[name=dbcategory]").each(function(i){
			if($(this).attr("checked") == true){
				ids.push($(this).val());
			}
		});
		
		return ids;
	}

	

//-->
</script>

<div class="column1" >

	<div class="box">
		<?php $this->beginWidget('zii.widgets.CPortlet', array('title'=>Yii::t('admin','Add Item')));?>
			<div class="box-content">
			
				<div id="stepLoading" class="hide">loading……</div>
				<div id="step0">
					<br />
					创建菜单提示：本菜单管理是为前台提供主导航菜单的相关内容，以下为创建步骤
					<ol>
						<li>确定是否创建根目录</li>
						<li>根据选择填写相应内容</li>
					</ol>
					
					单击下一步，选择备份方式<br /><br />
					<button type="button" class="button">下一步</button>
				</div>
				<div id="step1" class="hide">
		
					<br />
					<p>
						选择创建目录方式：
						<select name="backupWay" id="backupWay">
							<option value="All">从数据分类中导入</option>							
							<option value="topmenu">创建顶级菜单</option>
							<option value="childmenu">创建子菜单</option>
						</select>
					</p>		
					<button type="button" class="button" onclick="back($(this));">上一步</button>
					<button type="button" class="button" onclick="chooseType();">下一步</button>	
				</div>
				
				<div id="step2" class="hide">
					<div id="menuform" class="hide">
						<?php $this->renderPartial('_menuform',array('model'=>$model));?>
							

						<div class="clear">
						<br />
						<button type="button" class="button" onclick="back($(this).parent().parent());">上一步</button>
						
						</div>	
						
					</div>
					<div id="dataAll" class="hide">
						选择要导入的分类数据：<br />
						（注：如已经导入过则不必再次导入，此菜单项会自动与数据分类保持同步）
						<br /><br />
						<?php foreach ($roots as $item):?>
						<input type="checkbox" name="dbcategory" value="<?php echo $item->cate_id;?>" /> <?php echo $item->cate_name;?>&nbsp;&nbsp;&nbsp;&nbsp;
						<?php endforeach;?>
						<div class="clear">
						<br />
						<button type="button" class="button" onclick="back($(this).parent().parent());">上一步</button>
						<button type="button" class="button" value="finish" onclick="backupAll();">开始导入</button>
						</div>
					</div>		
				</div>				
			</div>
		<?php $this->endWidget();?>
	</div>
</div>

<div class="column2">
	<div class="box">
		<?php $this->beginWidget('zii.widgets.CPortlet', array('title'=>Yii::t('admin','Menu Items')));?>
			<div class="box-content" id="dblist">
			<ul style="margin:0px;padding:0px;margin-bottom:30px;background:#ffffff;">
				<?php foreach ($dataProvider as $data):?>	
				<li><?php echo $data['deep']==0?'|':''; for($i=0;$i<$data['deep']-1;$i++):?>－－<?php endfor;?><?php echo $data['name'];?></li>
				<?php endforeach;?>
			</ul>			
			</div>		
		<?php $this->endWidget();?>	
	</div>

</div>